package com.yanqu.road.server.cmd.activity.commonteam;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonTeamProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.commonteam.CommonTeam;
import com.yanqu.road.server.manager.activity.commonteam.CommonTeamActivity;
import com.yanqu.road.server.manager.activity.commonteam.CommonTeamMgr;
import com.yanqu.road.server.manager.activity.commonteam.pb.CommonTeamPb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C2_COMMON_TEAM_GET_TEAM_INFO, desc = "通用组队-获取队伍信息（根据队伍ID）")
public class CrossCommonTeamGetTeamInfoCmd extends CrossUnionCommand {

    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }
    
    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonTeamProto.CommonTeamGetTeamInfoReqMsg reqMsg = CommonTeamProto.CommonTeamGetTeamInfoReqMsg.parseFrom(packet.getBytes());
        CommonTeamProto.CommonTeamGetTeamInfoRespMsg.Builder respMsg = CommonTeamProto.CommonTeamGetTeamInfoRespMsg.newBuilder();
        //获取活动
        CommonTeamActivity activity = CommonTeamMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_COMMON_TEAM_TEAM_ACTIVITY_NOT_EXIST);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_COMMON_TEAM_GET_TEAM_INFO, respMsg));
            return;
        }
        //获取队伍列表
        CommonTeam team = activity.getTeam(reqMsg.getTeamId());
        //返回
        respMsg.setRet(0);
        if (team != null) {
            respMsg.setTeam(CommonTeamPb.buildCommonTeamData(team, true, false));
            respMsg.setApplyFlag(team.checkInApply(packet.getPlayerId()));
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_COMMON_TEAM_GET_TEAM_INFO, respMsg));
    }

    @Override
    public void sendData() {}
}
